#ifndef TCP_CONNECTION
#define TCP_CONNECTION

#include "event_loop.h"
#include "channel.h"
#include "buffer.h"
#include "tcp_server.h"

struct tcp_connection
{
    struct event_loop *eloop;
    struct channel *chan;
    char *name;
    struct buffer *input_buffer;
    struct buffer *out_buffer;
    connection_completed_callback_t connection_completed_callback;
    message_callback_t message_callback;
    write_completed_callback_t write_completed_callback;
    connection_closed_callback_t connection_closed_callback;

    void *data;
    void *reques;
    void *response;
};

struct tcp_connection *tcp_connection_new(int fd, struct event_loop *eloop,
                                          connection_completed_callback_t connection_completed_callback,
                                          message_callback_t message_callback,
                                          write_completed_callback_t write_completed_callback,
                                          connection_closed_callback_t connection_closed_callback);

int tcp_connection_send_data(struct tcp_connection *conn, void *data, int size);

int tcp_connection_send_buffer(struct tcp_connection *conn, struct buffer *buf);

void tcp_connection_shutdown(struct tcp_connection *conn);

#endif